﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RoleAdd.aspx.cs" Inherits="BySoft.Web.Site.SysManage.RoleAdd"
    MasterPageFile="~/MastePage/SubEmptyMaster.Master" %>

<%@ MasterType VirtualPath="~/MastePage/SubEmptyMaster.Master" %>
<%@ Register Assembly="OneSoft.Web" Namespace="OneSoft.Web.UI.WebControls" TagPrefix="asp" %>
<asp:Content ContentPlaceHolderID="EmptyMasteCPH" runat="server" ID="cphContent">
    <script language="javascript" type="text/javascript">

        $(function () {
            $("#tabs").tabs({ show: function (event, ui) { iframeAutoFit(); } });
        });

        //        function showtab(type) {
        //            if (type == "1") {
        //                document.getElementById('div1').style.display = "";
        //                document.getElementById('div2').style.display = "none";
        //                document.getElementById('tab1').className = "goodsDetailTab showall active";
        //                document.getElementById('tab2').className = "goodsDetailTab";
        //                iframeAutoFit();
        //            }
        //            if (type == "2") {
        //                document.getElementById('div1').style.display = "none";
        //                document.getElementById('div2').style.display = "";
        //                document.getElementById('tab2').className = "goodsDetailTab showall active";
        //                document.getElementById('tab1').className = "goodsDetailTab";
        //                iframeAutoFit();
        //            }
        //        }

        function CheckAll(con) {

            var dom = document.getElementById("<%=sgvRights.ClientID %>").getElementsByTagName("*");

            for (i = 0; i < dom.length; i++) {
                if (dom[i].tagName == "INPUT" && dom[i].type.toLowerCase() == "checkbox") {
                    dom[i].checked = document.getElementById(con.id).checked;
                }
            }

        }

        function CheckRowAll(con) {
            var dom = document.getElementById("<%=sgvRights.ClientID %>").getElementsByTagName("*");

            for (i = 0; i < dom.length; i++) {
                if (dom[i].tagName == "INPUT" && dom[i].type.toLowerCase() == "checkbox") {
                    var temp1 = dom[i].id.split("_");
                    var temp2 = con.id.split("_");
                    if (temp1[3] == temp2[3]) {

                        dom[i].checked = document.getElementById(con.id).checked;
                    }
                }
            }
        }

        function CheckColumnAll(con) {
            var dom = document.getElementById("<%=sgvRights.ClientID %>").getElementsByTagName("*");

            for (i = 0; i < dom.length; i++) {
                if (dom[i].tagName == "INPUT" && dom[i].type.toLowerCase() == "checkbox") {
                    var temp1 = dom[i].id.split("_");
                    var temp2 = con.id.split("_");
                    if (temp1[4] + "All" == temp2[4]) {

                        dom[i].checked = document.getElementById(con.id).checked;
                    }
                }
            }
        }

        function CheckSingle(con) {
            var dom = document.getElementById("<%=sgvRights.ClientID %>").getElementsByTagName("*");
            var temp = con.id.split("_");
            if (!document.getElementById(con.id).checked) {
                var n = 0;
                for (i = 0; i < dom.length; i++) {
                    if (dom[i].tagName == "INPUT" && dom[i].type.toLowerCase() == "checkbox") {
                        if (n == 0) {
                            dom[i].checked = false;
                        }
                        n = 1;
                        var temp1 = dom[i].id.split("_");

                        if (temp1[3] == temp[3] && temp1[4] == "cbRowAll") {

                            dom[i].checked = false;
                        }
                        if (temp1[4] == temp[4] + "All") {

                            dom[i].checked = false;
                        }
                    }
                }
                //返回查看权限的同时,返回其他权限
                if (temp[4] == "cbView") {
                    if (document.getElementById(con.id.replace("cbView", "cbAdd")) != null) {
                        document.getElementById(con.id.replace("cbView", "cbAdd")).checked = false;
                    }
                    if (document.getElementById(con.id.replace("cbView", "cbDel")) != null) {
                        document.getElementById(con.id.replace("cbView", "cbDel")).checked = false;
                    }
                    if (document.getElementById(con.id.replace("cbView", "cbUpdate")) != null) {
                        document.getElementById(con.id.replace("cbView", "cbUpdate")).checked = false;
                    }
                    if (document.getElementById(con.id.replace("cbView", "cbExport")) != null) {
                        document.getElementById(con.id.replace("cbView", "cbExport")).checked = false;
                    }
                    if (document.getElementById(con.id.replace("cbView", "cbApprove")) != null) {
                        document.getElementById(con.id.replace("cbView", "cbApprove")).checked = false;
                    }
                }
            }
            else {
                var checkrow = true;
                var checkcloumn = true;
                var checkall = true;
                for (i = 0; i < dom.length; i++) {
                    if (dom[i].tagName == "INPUT" && dom[i].type.toLowerCase() == "checkbox") {
                        var temp1 = dom[i].id.split("_");
                        //行是否都选中                      
                        if (temp1[3] == temp[3] && temp1[4] != "cbRowAll") {
                            if (dom[i].checked == false) {
                                checkrow = false;

                            }
                        }
                        //列是否都选中
                        if (temp1[4] == temp[4]) {
                            if (dom[i].checked == false) {
                                checkcloumn = false;
                            }
                        }
                    }


                }

                document.getElementById(temp[0] + "_" + temp[1] + "_" + temp[2] + "_" + temp[3] + "_cbRowAll").checked = checkrow;
                document.getElementById(temp[0] + "_" + temp[1] + "_" + temp[2] + "_ctl01_" + temp[4] + "All").checked = checkcloumn;
                document.getElementById(temp[0] + "_" + temp[1] + "_" + temp[2] + "_ctl01_cbAll").checked = (checkrow && checkcloumn);

                //设置其他权限时,自动设置查看权限
                if (temp[4] == "cbAdd" || temp[4] == "cbDel" || temp[4] == "cbUpdate" || temp[4] == "cbExport" || temp[4] == "cbApprove") {
                    if (document.getElementById(temp[0] + "_" + temp[1] + "_" + temp[2] + "_" + temp[3] + "_cbView") != null) {
                        document.getElementById(temp[0] + "_" + temp[1] + "_" + temp[2] + "_" + temp[3] + "_cbView").checked = true;
                    }

                }   

            }
        }

        function OpenNew() {
            ShowTopDialog('成员选择', '../SysManage/RoleMenber.aspx', 'closeCallback();', 780, 580); return false;

        }

        function closeCallback() {


            document.getElementById("<%=btnAdd.ClientID %>").click();

            iframeAutoFit(); //iframe自动伸展，解决滚动问题
        }
        //confirm回调函数
        function confirmCallback(control) {
            var obj = document.getElementById(control);
            if (obj != null)
                obj.click();
        }
    </script>
    <h1 class="tit">
        系统管理 >> <a href="RoleList.aspx">角色管理</a> >> 新增</h1>
    <div class="tableStyle2">
        <table cellpadding="0" cellspacing="0">
            <tr>
                <th class="left2" style="line-height: normal">
                    <span class="red">*</span>角色名称：
                </th>
                <td colspan="3" style="line-height: normal">
                    <asp:TextBox ID="txtRoleName" runat="server" MaxLength="20"  CssClass="text ui-widget-content ui-corner-all"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvRoleName" runat="server" ErrorMessage="请输入角色名称！"
                        ControlToValidate="txtRoleName" Display="None" ValidationGroup="gSubmit">*</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <th style="line-height: normal">
                    角色描述：
                </th>
                <td colspan="3" style="line-height: normal">
                    <asp:TextBox ID="txtDesc" runat="server" TextMode="MultiLine" Columns="50" Rows="4"
                         CssClass="text ui-widget-content ui-corner-all"></asp:TextBox>
                    <asp:RegularExpressionValidator ID="rfvDesc" runat="server" ControlToValidate="txtDesc"
                        ValidationGroup="gSubmit" Display="None" ErrorMessage="描述不能超过200个字符！" ValidationExpression="[\w\W]{0,200}"></asp:RegularExpressionValidator>
                </td>
            </tr>
        </table>
    </div>
    <div>
        <div id="tabs">
            <ul>
                <li><a href="#tabs-1">角色权限</a></li>
                <li><a href="#tabs-2">角色成员</a></li>
            </ul>
            <%-- 角色权限--%>
            <div id="tabs-1" class="tableStyle">
                <asp:SGridView runat="server" ID="sgvRights" Width="100%" ShowActionToolBar="false"
                    AutoGenerateColumns="false" AllowCascade="false" DataKeyNames="ModulePrimaryID,MODULEID,PAGETYPE,MODULERIGHTS,DATARIGHTS"
                    OnRowDataBound="sgvRights_RowDataBound">
                    <Columns>
                        <asp:TemplateField>
                            <HeaderStyle Width="450px" />
                            <ItemStyle Width="450px" />
                            <HeaderTemplate>
                                功能名
                            </HeaderTemplate>
                            <ItemTemplate>
                                <div style="text-align: left">
                                    <%#GetModuleName(Eval("MODULENAME"))%></div>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <HeaderStyle Width="200px" />
                            <ItemStyle Width="200px" />
                            <HeaderTemplate>
                                <asp:CheckBox ID="cbAll" runat="server" onclick="CheckAll(this)" />全选</HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="cbRowAll" runat="server" onclick="CheckRowAll(this)" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <HeaderStyle Width="200px" />
                            <ItemStyle Width="200px" />
                            <HeaderTemplate>
                                <asp:CheckBox ID="cbViewAll" runat="server" onclick="CheckColumnAll(this)" />查看</HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="cbView" runat="server" onclick="CheckSingle(this)" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <HeaderStyle Width="200px" />
                            <ItemStyle Width="200px" />
                            <HeaderTemplate>
                                <asp:CheckBox ID="cbAddAll" runat="server" onclick="CheckColumnAll(this)" />新增</HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="cbAdd" runat="server" onclick="CheckSingle(this)" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <HeaderStyle Width="200px" />
                            <ItemStyle Width="200px" />
                            <HeaderTemplate>
                                <asp:CheckBox ID="cbDelAll" runat="server" onclick="CheckColumnAll(this)" />删除</HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="cbDel" runat="server" onclick="CheckSingle(this)" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField>
                            <HeaderStyle Width="200px" />
                            <ItemStyle Width="200px" />
                            <HeaderTemplate>
                                <asp:CheckBox ID="cbUpdateAll" runat="server" onclick="CheckColumnAll(this)" />修改</HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="cbUpdate" runat="server" onclick="CheckSingle(this)" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField >
                            <HeaderStyle Width="200px" />
                            <HeaderTemplate>
                                <asp:CheckBox ID="cbApproveAll" runat="server" onclick="CheckColumnAll(this)" />审核</HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="cbApprove" runat="server" onclick="CheckSingle(this)" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField >
                            <HeaderStyle Width="200px" />
                            <ItemStyle Width="200px" />
                            <HeaderTemplate>
                                <asp:CheckBox ID="cbExportAll" runat="server" onclick="CheckColumnAll(this)" />导出</HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="cbExport" runat="server" onclick="CheckSingle(this)" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:SGridView>
            </div>
            <div id="tabs-2" class="tableStyle">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <div>
                            <table width="100%">
                                <tr>
                                    <td>
                                        <div align="right">
                                            <a href="##" onclick="OpenNew()" title="添加">
                                                <img src="../../App_Themes/Common_CSS/images/Add_new.gif" alt="添加" style="padding-bottom: 3px;
                                                    padding-right: 1px;" /></a></div>
                                        <asp:Button ID="btnAdd" runat="server" Text="Button" OnClick="btnAdd_Click" Style="display: none" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <div class="tableStyle">
                                            <asp:SGridView runat="server" ID="sgvMember" Width="100%" ShowActionToolBar="false"
                                                AutoGenerateColumns="false" AllowCascade="false" DataKeyNames="ID" OnRowCommand="sgvMember_RowCommand"
                                                OnRowDataBound="sgvMember_RowDataBound">
                                                <Columns>
                                                    <asp:BoundField DataField="DISPLAY_ID" HeaderText="账号" ItemStyle-Width="200px" HeaderStyle-HorizontalAlign="Center"
                                                        HeaderStyle-Width="200px" ItemStyle-HorizontalAlign="Center" />
                                                    <asp:BoundField DataField="NAME" HeaderText="姓名" ItemStyle-Width="200px" HeaderStyle-HorizontalAlign="Center"
                                                        HeaderStyle-Width="200px" ItemStyle-HorizontalAlign="Center" />
                                                    <asp:TemplateField>
                                                        <HeaderStyle Width="200px" />
                                                        <ItemStyle Width="200px" />
                                                        <HeaderTemplate>
                                                            删除</HeaderTemplate>
                                                        <ItemTemplate>
                                                            <asp:ImageButton ImageUrl="~/App_Themes/Common_CSS/images/delete_small.gif" runat="server"
                                                                ID="ibtnDel" />
                                                            <asp:Button ID="btnDel" runat="server" CssClass="Hidden" CommandArgument='<%#Eval("ID") %>'
                                                                CommandName="del" />
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                </Columns>
                                            </asp:SGridView>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
        </div>
    </div>
    <div class="controlBar" align="center">
        <table cellpadding="0" cellspacing="0" style="width: 140px; margin: 0 auto;">
            <tr>
                <td width="30%">
                    <label class="btnStylec png_bg">
                        <asp:Button ID="btnSubmit" runat="server" Text="确定" OnClick="btnSubmit_Click" ValidationGroup="gSubmit"
                            Width="60px" />
                    </label>
                    <label class="btnStyleb png_bg">
                        <input type="button" id="btnCancel" value="返回" onclick="window.location='/SysManage/RoleList.aspx'"
                            style="width: 60px;" />
                    </label>
                </td>
            </tr>
        </table>
    </div>
</asp:Content>
